package com.dl.mall.service;

import com.dl.mall.service.admin.ProductService_Admin;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 多线程服务类
 * @author DL
 * @create 2022-05-10 11:22
 */
@Service
@Slf4j
public class AsyncServiceImpl implements AsyncService {

    @Resource
    private ProductService_Admin productServiceAdmin;

    @Override
    @Async("taskExecutor")
    public void asyncUpload(String spuJson,
                            String skuJson,
                            MultipartFile mainImg,
                            MultipartFile[] subImg,
                            MultipartFile[] specsImg) {
        long startTime = System.currentTimeMillis();
        boolean addProduct = productServiceAdmin.addProduct(spuJson, skuJson, mainImg, subImg, specsImg);
        long endTime = System.currentTimeMillis();
        log.info("上传商品共耗时：{}ms", endTime - startTime);
    }
}

